﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Migrator.Framework;
using System.IO;
using System.Reflection;

namespace PlanoAulaHelper.Util
{
    [Migration(1)]
    public class _1_Version : Migration
    {
        public override void Up()
        {
            if (!Database.GetTables().Contains("DiaUtil"))
            {
                Database.BeginTransaction();
                try
                {

                    StringBuilder conteudoArquivo = new StringBuilder();
                    string sql = "";
                    using (Stream fs = Assembly.GetExecutingAssembly().GetManifestResourceStream("PlanoAulaHelper.UpgradeDataBase.Script.sql"))
                    {
                        sql = new StreamReader(fs).ReadToEnd();
                        //byte[] b = new byte[1];
                        //UnicodeEncoding temp = new UnicodeEncoding();
                        //while (fs.Read(b, 0, b.Length) > 0)
                        //{
                        //    conteudoArquivo.Append(temp.GetString(b));
                        //}

                    }

                    //string sql = conteudoArquivo.ToString();
                    Database.ExecuteNonQuery(sql);
                    Database.Commit();
                }
                catch
                {
                    Database.Rollback();
                    throw;
                }
            }
        }

        public override void Down()
        {
          
        }
    }
}
